package com.jiufen.Controller;


import com.jiufen.Pojo.Emp;
import com.jiufen.Pojo.LoginInfo;
import com.jiufen.Pojo.Result;
import com.jiufen.Service.EmpService;
import com.jiufen.anno.LogOperate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
@Slf4j
public class LoginController {


    @Autowired
    private EmpService empService;
    @LogOperate
    @PostMapping
    public Result login(@RequestBody  Emp emp) {
        log.info("登录参数如下：{}", emp);
        LoginInfo loginInfo = empService.getEmpByUsernameAndPassword(emp);
        if (loginInfo != null) {
            return Result.success(loginInfo);
        } else {
            return Result.error("用户名或密码错误");
        }
    }
}
